package com.study.d6_thread_pool;

import java.util.concurrent.*;

public class Test4 {
    public static void main(String[] args) {
        //使用线程池工具类创建线程池对象（不建议用）
          //底层基于线程池ExecutorService的实现类：ThreadPoolExecutor
          //不适合做大型互联网场景的线程池方案
          //建议使用ThreadPoolExecutor指定线程池参数，这样可以
            //明确线程池的运行规则，规避资源耗尽的风险
        ExecutorService pool = Executors.newFixedThreadPool(3);
        Future<String> submit1 = pool.submit(new MyCallable(100));
        Future<String> submit2 = pool.submit(new MyCallable(200));
        Future<String> submit3 = pool.submit(new MyCallable(300));

        try {
            String s = submit1.get();
            System.out.println(s);
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            String s = submit2.get();
            System.out.println(s);
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            String s = submit3.get();
            System.out.println(s);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
